package org.datacoder.geocoding.datastructures.intervals

import org.datacoder.geocoding.datastructures.geoshapes.*
import org.datacoder.geocoding.datastructures.points.*
import org.datacoder.geocoding.datastructures.util.*
import org.datacoder.geocoding.jurisdiction.*

class LayeredSegmentRangeTreeNode {

    LayeredSegmentRangeTreeNode left = null
    LayeredSegmentRangeTreeNode right = null
    double leftValue
    double rightValue
    int type
    Set<Jurisdiction> jurisdictions
    RangeTree geoPoints

    public LayeredSegmentRangeTreeNode(int type){
        this.type = type
        jurisdictions = new HashSet<Jurisdiction>()
    }
    public boolean containsPoint(double point){
        return ((leftValue <= point) && (point <= rightValue))
    }
    public void addJurisdiction(Jurisdiction juris){
        jurisdictions.add(juris)
    }
    public void lock(){
        geoPoints = new RangeTree(jurisdictions, GeoShape.getOtherType(type))
        jurisdictions.clear()
        jurisdictions = null
    }
    public Set<Jurisdiction> findPointsWithinInterval(double min, double max){
        return geoPoints.findPointsWithinInterval(min, max)
    }
    
}

